#include "header.h"
Status isEmptySatck(SqStack &s){
    if(s.base == s.top)
        return IS_EMPTY;
    else
        return NO_EMPTY;
}

void initSatck(SqStack & s){
    s.base = (ElemType*)malloc(INIT_STACK_SIZE * sizeof(ElemType));
    if(!s.base)
        exit(0);
    s.top = s.base;
    s.stacksize = INIT_STACK_SIZE;
}
void pushStack(SqStack & s,ElemType e){
    if((s.top - s.base) == s.stacksize){
        s.base = (ElemType*)realloc(s.base,(STACK_INCREMENT + s.stacksize)*sizeof(ElemType));
        if(!s.base)
            return ;
        s.top = s.base + s.stacksize;
        s.stacksize += STACK_INCREMENT;
    }
    *(s.top)++ = e; /*为什么要++*/
}
ElemType popStack(SqStack & s){
    if(s.base == s.top)
        return ERROR;
    return *(--s.top);
}

int main(void)
{
    SqStack sqstack;
    initSatck(sqstack);

    int input = 0;
    /*为什么会乱码*/
    cout << "将十进制整数n转换为"<<RADIX<<"进制数，请输入：n（≥0）="<<endl;
    scanf("%d",&input);
    while(input){
        pushStack(sqstack,input % RADIX);
        input = input / RADIX;
    }

    while(isEmptySatck(sqstack) != IS_EMPTY){
        cout<<popStack(sqstack);
    }

    cout<<endl;
    return 0;
}
